#include<bits/stdc++.h>
using namespace std;
int d[100005],v[100005],a[100005],p[100005],q[100005],e[100005],c[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        for(int i = 1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i = 1;i<=m;i++){
            cin>>p[i];
        }
        int sum=0,cnt;
        for(int i = 1;i<=n;i++){
            if(v[i]>V&&a[i]>=0){
                cnt=d[i];
            }
            else if(v[i]<=V&&a[i]<=0)continue;
            else {
                int tmp=(V*V-v[i]*v[i])/(2*a[i]);
                if(tmp>L-d[i])continue;
                cnt=d[i]+tmp;
            }
            int j=0,k=0,f=cnt;
            while(cnt){
                if(v[i]<=V){
                    if(p[j]<=cnt)j++;
                    else cnt=0;
                }
                else if(v[i]>V&&a[i]>=0){
                    if(p[j]<cnt)j++;
                    else cnt=0;
                }
                else {
                    if(p[k]<d[i])k++;
                    if(p[j+1]<=cnt)j++;
                    else cnt=0;
                }
            }
            cout<<k<<" "<<j<<"\n";
            if(v[i]<=V)if(p[j]>f){
                sum++;
                q[sum]=p[j],e[sum]=p[m];
                c[sum]=0;
            }
            else if(p[j]>=d[i]&&p[j]<=f){
                sum++;
                q[sum]=p[k],e[sum]=p[j];
                c[sum]=0;
            }
        }
        cout<<sum<<" ";
        for(int i = 1;i<=sum;i++){
            for(int w=i+1;w<=sum;w++){
                if(c[w])continue;
                if(q[w]>=e[i]){
                   q[i]=max(q[i],q[w]);
                   m++;
                   c[w]=1;
                }
            }
        }
        cout<<m-sum<<"\n";
    }
    return 0;
}
